//! Vertex normal
varying vec3 v_normal;

void main()
{
    // Normalize the vertex normal again
    vec3 normal = normalize( v_normal );
    // Pixel position relative to the center of the pointsprite
    vec2 pixel_pos = vec2( gl_PointCoord.s - 0.5, gl_PointCoord.t - 0.5 );
    // Pixel depth distance from the center
    float dz = normal.x * pixel_pos.x / normal.z + normal.y * pixel_pos.y / normal.z;
    // Calculate distance from the center of the pointsprite
    float sqdist = pixel_pos.x * pixel_pos.x + pixel_pos.y * pixel_pos.y + dz * dz;

    // Only draw pixels that are in the ellipse
    if (sqdist < 0.25) {
        // Discard red pixels
        if (gl_Color == vec4( 1.0, 0.0, 0.0, 1.0 )) {
            discard;
        } else {
            gl_FragColor = gl_Color;
        }
    } else {
        discard;
    }
}
